package com.kuaikan.cnbeta.activity;

import net.tsz.afinal.annotation.view.ViewInject;

import android.app.ProgressDialog;
import android.os.Handler;
import android.webkit.WebSettings.LayoutAlgorithm;
import android.webkit.WebView;

import com.bsi.app.BaseActivity;
import com.bsi.app.widget.DialogUtil;
import com.kuaikan.cnbeta.R;
import com.kuaikan.cnbeta.pojo.News;
import com.kuaikan.cnbeta.util.Const;
import com.kuaikan.cnbeta.util.Msg;

public class NewsShowActivity extends BaseActivity {

	@ViewInject(id = R.id.wvContent)
	WebView wvContent;
	News news;
	ProgressDialog waitingDialog;

	@Override
	public void setCurrentContentView() {
		setContentView(R.layout.act_new_show);
	}

	Handler handler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case Msg.DONE:
				wvContent.loadDataWithBaseURL(null, news.getContent(),
						"text/html", "utf-8", null);
				wvContent.getSettings().setLayoutAlgorithm(
						LayoutAlgorithm.SINGLE_COLUMN);
				wvContent.getSettings().setJavaScriptEnabled(false);
				// wvContent.setWebChromeClient(new WebChromeClient());
				waitingDialog.dismiss();
				new Thread() {
					public void run() {
						srvcFactory.getNewsSrvc().updateContent(news);
					};
				}.start();
				break;

			default:
				break;
			}
		};
	};

	@Override
	protected void onCreate(android.os.Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initData();
	};

	void initData() {
		waitingDialog = DialogUtil.showPleaseWaitingProgressDialog(this);
		new Thread() {
			public void run() {
				news = (News) getIntent().getSerializableExtra("news");
				try {
					news = srvcFactory.getNewsSrvc().getNewsContent(news);
					handler.sendEmptyMessage(Msg.DONE);
				} catch (Exception e) {
					e.printStackTrace();
					handler.sendEmptyMessage(Msg.TIMEOUT);
				}

			};
		}.start();
	}

	@Override
	protected void onResume() {
		super.onResume();

	}

	@Override
	protected void onStop() {
		super.onStop();
		waitingDialog.dismiss();
	}

}
